from django.db import models

# Create your models here.
from labels.models import Labels
from mlh.utils.models import BaseModel
from users.models import User


class Question(BaseModel):
    STATUS = (
        (1, "已回答"),
        (0, "待回答")
    )

    title = models.CharField(max_length=32, verbose_name="标题", null=True)
    time = models.DateTimeField(verbose_name="提问时间", null=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="提问人", related_name="questioner", null=True)
    pageview = models.IntegerField(verbose_name="浏览量", null=True)
    use_number = models.IntegerField(verbose_name="有用的数量", null=True)
    content = models.TextField(verbose_name="问题内容", null=True)
    labels = models.ManyToManyField(to=Labels, db_table='q_l')
    answer_number = models.IntegerField(verbose_name="回答的数量", null=True)
    status = models.SmallIntegerField(choices=STATUS, null=True, verbose_name="问题状态")
    comment_number = models.IntegerField(verbose_name="评论数", null=True)

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'tb_question'
        verbose_name = '问题'
        verbose_name_plural = verbose_name
